<template>
    <div class="app-container">
  
      <div class="filter-container">
        <el-select
          v-model="listQuery.pkg"
          style="width: 150px"
          class="filter-item"
          @change="handleFilter"
        >
           <el-option label="全部包" :value="''" />
          <el-option v-for="(v, k) in pkgs" :key="k" :label="v" :value="k" />
          
        </el-select>
        <el-input
          v-model="listQuery.message"
          placeholder="请输入message"
          style="width: 220px;"
          class="filter-item"
          @keyup.enter.native="handleFilter"
        />
        <el-button
         plain size="small"
          v-waves
          class="filter-item"
          type="primary"
          icon="el-icon-search"
          @click="handleFilter"
        >搜索</el-button>

        <el-button
         plain size="small"
          v-waves
          class="filter-item btn"
          type="primary"
          icon="el-icon-refresh"
          @click="handleCancel"
        >重置</el-button>
      </div>
  
      <el-table
        :key="tableKey"
        v-loading="listLoading"
        :data="list"
        border
        fit
        highlight-current-row
        style="width: 100%;"
      >
        <el-table-column label="id" min-width="50" align="center">
          <template slot-scope="{row}">
            <span>{{ row.err_id }}</span>
          </template>
        </el-table-column>
        <el-table-column label="包" min-width="50" align="center">
          <template slot-scope="{row}">
            <span>{{ pkgs[row.pkg]}}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column label="类型" min-width="50" align="center">
          <template slot-scope="{row}">
            <span>{{ row.type_ }}</span> 
          </template>
        </el-table-column> -->
        <el-table-column label="messsage" min-width="80" align="center">
          <template slot-scope="{row}">
            <span>{{ row.message }}</span>
          </template>
        </el-table-column>
        
        <el-table-column label="错误详情" min-width="" align="center">
          <template slot-scope="{row}">
            <span>
              <el-popover
                placement="bottom"
                width="400"
                trigger="click"
                :content="row.stack">
                <el-button slot="reference">错误详情</el-button>
              </el-popover>
            </span> 
          </template>
        </el-table-column>
        <el-table-column label="客户端版本" min-width="" align="center">
          <template slot-scope="{row}">
            <span>{{ row.version }}</span> 
          </template>
        </el-table-column>
        <el-table-column label="创建时间" min-width="" align="center">
          <template slot-scope="{row}">
            <span>{{ row.create_time }}</span>
          </template>
        </el-table-column>

      </el-table>
  
      <pagination
        v-show="total > 0"
        :total="total"
        class="pageShow"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.limit"
        @pagination="getList"
      />

    </div>
  </template>
  
  <script>
  import {
    getErrorReport,
    getPkgList
  } from "@/api/adv_admin/config";
  // import {
  //   quickLogin,
  // } from "@/api/admin/control";addProxyOrqudao
  import waves from "@/directive/waves"; // waves directive
  import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
  import { Message } from "element-ui";
  
  export default {
    name: "Control",
    components: { Pagination },
    directives: { waves },
    data() {
      return {
        tableKey: 0,
        list: null,
        total: 0,
        listLoading: true,
        listQuery: {
          page: 1,
          limit: 20,
          pkg: "",
          error_type: "",
          message: ""
        },
        error_type: {},
        pkgs: {}
      };
    },
    created() {
      this.getPkgs()
      this.getList();
    //   this.setDialogWidth();
    },
    mounted() {
      window.onresize = () => {
        return (() => {
          this.setDialogWidth();
        })();
      };
    },
    methods: {
      setDialogWidth() {
        const val = document.body.clientWidth;
        const def = 600; // 默认宽度
        if (val < def) {
          this.dialogWidth = "100%";
        } else {
          this.dialogWidth = def + "px";
        }
      },
      getPkgs(){
        getPkgList().then((res)=>{
          this.pkgs = res.DATA.list
        })
      },
      getList() {
        this.listLoading = true;
        getErrorReport(this.listQuery).then((response) => {
          this.list = response.DATA.list;
          this.total = response.DATA.total;
          this.listLoading = false;
          this.error_type = response.DATA.error_type
        });
      },
      handleFilter() {
        this.listQuery.page = 1;
        this.getList();
      },
      handleCancel(){
        this.listQuery = {
          page: 1,
          limit: 20,
          pkg: "",
          error_type: "",
          message: ""
        }
        this.getList()
      }
    
    },
  };
  </script>
  
  <style lang="scss" scoped>
  .show-pwd {
    position: absolute;
    right: 10px;
    top: 0;
    font-size: 16px;
    color: #ccc;
    cursor: pointer;
    user-select: none;
  }
  .push {
    display: inline-block;
    width: 20px;
    height: 20px;
    line-height: 20px;
    text-align: center;
    vertical-align: middle;
    cursor: pointer;
    margin-left: 5px;
  }
  .pageHidden {
    display: none;
  }
  .btn {
    margin-left: 0;
  }
  .fullwidth {
    width: 450px;
    margin-left: 50px;
  }
  @media (max-width: 550px) {
    .pageShow {
      display: none;
    }
    .pageHidden {
      display: block;
    }
    .fullwidth {
      width: 100%;
      margin-left: 0;
    }
  }
  </style>
  